package cn.xmy.demo01.controller;

import cn.xmy.demo01.pojo.Address;
import cn.xmy.demo01.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;

@RestController
public class AddressController {
    @Autowired
    AddressService addressService;
    // 处理 POST 请求，地址添加功能
    @PostMapping("/addAddress")
    public String addAddress(@RequestBody Address address) {
        try {
            // 调用 service 层的方法来处理地址添加
            int rows = addressService.addAddress(address);
            if (rows > 0) {
                return "success";  // 返回成功消息
            } else {
                return "failure";  // 返回失败消息
            }
        } catch (SQLException | ClassNotFoundException e) {
            e.printStackTrace();
            return "error";  // 返回错误消息
        }
    }
}

